<?php

// +----------------------------------------------------------------------
// | ShintianCMS
// +----------------------------------------------------------------------
// | Copyright (c) 2011 Shintian All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: ljt <ljt1002@gmail.com>
// +----------------------------------------------------------------------
class IndexAction extends BaseAction {

    function index() {
        if (isset($_SESSION [C('USER_AUTH_KEY')])) {
            //显示菜单项
            $menu = array();
            
            //读取应用分组
            $gmodel = M("Group");
            $gwhere ['status'] = 1;
            $gwhere ['show'] = 1;
            $appgrouplist = $gmodel->where($gwhere)->field('id,name,title')->order('sort asc')->select();
            $this->assign('appgroup', $appgrouplist);

            //读取数据库模块列表生成菜单项
            $node = M("Node");
            $id = $node->getField("id");
            $where ['level'] = 2;
            $where ['status'] = 1;
            $where ['pid'] = $id;
            $list = $node->where($where)->field('id,name,group_id,title')->order('sort asc')->select();
            if (C('USER_AUTH_TYPE') == 2) {
                //加强验证和即时验证模式 更加安全 后台权限修改可以即时生效
                //通过数据库进行访问检查
                $accessList = RBAC::getAccessList($_SESSION[C('USER_AUTH_KEY')]);
            } else {
                // 如果是管理员或者当前操作已经认证过，无需再次认证
                if ($_SESSION[$accessGuid]) {
                    return true;
                }
                //登录验证模式，比较登录后保存的权限访问列表
                $accessList = $_SESSION['_ACCESS_LIST'];
            }
            //dump($accessList);
            foreach ($list as $key => $module) {
                if (isset($accessList [strtoupper(APP_NAME)] [strtoupper($module ['name'])]) || $_SESSION ['st_administrator']) {
                    //设置模块访问权限
                    $module ['access'] = 1;
                    $menu [$key] = $module;
                }
            }
            if (!empty($_GET ['tag'])) {
                $this->assign('menuTag', $_GET ['tag']);
            }
            //dump($menu);
            $this->assign('menu', $menu);
        }
        C('SHOW_RUN_TIME', false); // 运行时间显示
        C('SHOW_PAGE_TRACE', false);
        $this->display();
    }

}

?>